package cn.kiliter.dao;

import cn.kiliter.model.OrderItem;
import cn.kiliter.utils.ManagerThreadLocal;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;
import java.util.List;

public class OrderItemDao {
    private QueryRunner qr=new QueryRunner();
    public void saveOrderItem(List<OrderItem> items) throws SQLException {
        String sql="insert into orderitem (order_id,product_id,buynum) values(?,?,?)";
        Object[][] params = new Object[items.size()][];
        for(int i=0;i<items.size();i++){
            OrderItem item = items.get(i);
            params[i] = new Object[]{item.getOrder().getId(),item.getProduct().getId(),item.getBuynum()};
        }

        QueryRunner qr=new QueryRunner();
        qr.batch(ManagerThreadLocal.getConnection(),sql,params);
    }



}
